using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Bll;

public partial class MasterPage : System.Web.UI.MasterPage
{
    public int flashbutton;

    protected void Page_Load(object sender, EventArgs e)
    {
        string title = this.Page.Title;
        switch (title)
        {
            case "Home":
                flashbutton = 1;
                break;
            case "Product":
                flashbutton = 2;
                break;
            case "Technology":
                flashbutton = 3;
                break;
            case "About Us":
                flashbutton = 4;
                break;
            case "Site Map":
                flashbutton = 5;
                break;
        }
        if (!IsPostBack)
        {
            ArrayList arr = (ArrayList)HttpContext.Current.Session["Login"];
            if (arr != null)
            {
                //lblRightUser.Text = "Welcome " + "<b>" + arr[0].ToString() + "</b>";
                lblMessage.Text = "Welcome " + "<b>" + arr[0].ToString() + "</b>";
                lbtnLogout.Visible = true;
                panelLogin.Visible = false;
            }
            else
            {
                panelLogin.Visible = true;
                lbtnLogout.Visible = false;
            }

        }
    }
    protected void btnSignIn_Click(object sender, EventArgs e)
    {
        AccountBll accBll = new AccountBll();

        ArrayList arraylist = accBll.getRightUsers(txtUsername.Text, txtPassword.Text);
        if (arraylist.Capacity > 0)
        {
            HttpContext.Current.Session.Remove("Login");
            HttpContext.Current.Session["Login"] = arraylist;
            if (arraylist[1].ToString().Trim() == "admin")
            {
                Response.Redirect("Admin/AdminPage.aspx");
            }
            //redirect to current page
            Uri MyUrl = Request.Url;
            Response.Redirect(MyUrl.PathAndQuery);
        }
        else
            lblMessage.Text = "Invalid Username or Password";
    }
    protected void lbtnForgotPassword_Click(object sender, EventArgs e)
    {
        Response.Redirect("ForgotPassword.aspx");
    }
    protected void lbtnSignUp_Click(object sender, EventArgs e)
    {
        Response.Redirect("signup.aspx");
    }
    protected void lbtnLogout_Click(object sender, EventArgs e)
    {
        HttpContext.Current.Session.Remove("Login");
        HttpContext.Current.Session.Remove("ShoppingCart");
        Response.Redirect("home.aspx");
    }
}
